

// 切换菜单
$('.Baby_Healthy_home_billing_left_dl>dd').on("click",function(){
    if($(this).attr('flage')=='true'){
        $(this).addClass("bgc_alert").siblings().removeClass("bgc_alert");
        var ddIndex = $(this).index();
        $('.js_cardListgroup').removeClass('hidden')
        $('.js_nocontent').addClass('hidden')
        if(ddIndex=="1"){
            $('.js_cardListgroup').find('.Baby_Healthy_home_billing_right_center_tit').text('储值卡')
            filterCardList(4)
        }else if(ddIndex=="2"){
            $('.js_cardListgroup').find('.Baby_Healthy_home_billing_right_center_tit').text('计次卡')
            filterCardList(5)
        }else if(ddIndex=="3"){
            $('.js_cardListgroup').find('.Baby_Healthy_home_billing_right_center_tit').text('自定义卡')
            DocData.initInitServiceList();
        }
    }
});


// 清空全部
$('.consumeListContains').on('click',".clearAll",function(){
    $('.Baby_Healthy_home_billing_left_dd').attr('flage',false).removeClass('bgc_alert');
    $(this).parents(".consumeListContains").addClass('hidden').siblings('.serachSelect').removeClass('hidden').siblings('.noticeImg').removeClass('hidden');
    $('.Baby_Healthy_home_billing_right_center').eq(0).removeClass('hidden').siblings(".Baby_Healthy_home_billing_right_center").addClass("hidden");
    $('.js_storeelm').find('.storeelm_checkbox').removeClass('checkBox_checked')
});

$('.consumeListContains').on('click','.saveBtnPay',function(){
    var d=baseFn.dialog({
        content:'确认保存该订单？',
        ok:function(){
            var _saveUrl=baseUrl.base+baseUrl.order;
            var _upData={
                userName:DocData.userName,
                userId:DocData.userId,
                bookingId:DocData.bookingId,
                doctorId: DocData.doctorId,
                subclinicId:DocData.subclinicId,
                patientId:DocData.patientId,
                orderTotalCost:DocData.cost,
                orderPayCost:DocData.pay,
                couponId:undefined,//优惠券
                cardId:[],//卡
                goodsList:[],
                serviceList:[]
            }
            if(DocData.orderId != ''){
                _saveUrl += 'updateOrderInfo',
                _upData.orderId = DocData.orderId
            }else{
                _saveUrl += 'saveOrderInfo'
            }

            for(var i=0;i<DocData.serviceIds.length;i++){
                var _ids= DocData.serviceIds[i]
                var _temp = DocData.serviceList.filter(function(val){
                    return val.serviceId == _ids
                })
                if(_temp.length != 0){
                    _upData.serviceList.push(_temp[0])
                }
            }
            if(_upData.serviceList.length == 0){
                baseFn.infoDialog('请至少选择一项推拿服务！')
                d.close()
                return false
            }
            for(var j=0;j<DocData.goodsIds.length;j++){
                var _ids= DocData.goodsIds[j]
                var _num = Number($('.js_project_wrap[rel=2]').find('.newAddBtn[rel='+_ids+']').find('span.jishuNum').text())
                var _temp = DocData.goodsList.filter(function(val){
                    return val.goodsId == _ids
                })
                if(_temp.length != 0){
                    _temp[0].orderNum = _num 
                    _upData.goodsList.push(_temp[0])
                }
            }
            $('.card_wrap').each(function(k,m){
                _upData.cardId.push($(m).find('.js_serviceSelCard').val())
            })
            _upData.cardId=_upData.cardId.join(',')
            //return false
            _upData.serviceList = JSON.stringify(_upData.serviceList);
            _upData.goodsList = JSON.stringify(_upData.goodsList);
            $.post(_saveUrl,_upData,function(res){
                if(res.code == 0){
                    baseFn.infoDialog('保存成功！')
                }else{
                    baseFn.infoDialog(res.msg)
                }
            },'json')
        }
    })
})
$('.consumeListContains').on('click','.gatheringBtn',function(){
    if(baseFn.notNull(DocData.cardId)){        
        DocData.orderdesc = $('.js_orderDesc').val()
        DocData.initOrder(DocData.cardId)
        baseFn.dialog({
            width:'40em',
            height:'65vh',
            title:'收银台',
            content:$('.gatheringlist'),
            okValue:'确认收款',
            ok:function(){
                var _upDatas={
                    cashierId:DocData.cashierId,
                    userId:DocData.userId,
                    cardId:DocData.cardId,
                    cardType:DocData.cardType,
                    doctorId:DocData.doctorId,
                    subclinicId:DocData.subclinicId,
                    payWay:DocData.payWay,
                    cardDesc:$('.js_orderDesc').val()
                }
                $.post(baseUrl.base+baseUrl.card+'saveUserCard',_upDatas,function(res){
                    if(res.code ==0){
                        var _txt='储值成功'
                        if(_upDatas.cardType == 5){
                            _txt = '开卡成功'
                        }
                        baseFn.infoDialog(_txt,function(){
                            baseFn.goPath('gotoOrder',{flag:2})
                        })
                        
                    }else{
                        baseFn.infoDialog(res.msg)
                    }
                },'json')
            }
        })
    }else{
        baseFn.infoDialog('请选择至少一项业务！')
    }
})
$('.payelm').on('click',function(){
    $(this).parents('.zccardelm').find('.payelm').removeClass('active')
    $(this).addClass('active')
    DocData.payWay=$(this).attr('rel')
})

baseFn.powerFn()


